#ifndef PROXY_CLIENT_HTTP_PARSER_H_
#define PROXY_CLIENT_HTTP_PARSER_H_

#include <string>
#include <vector>
#include <boost/logic/tribool.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/asio/coroutine.hpp>
#include <boost/asio/buffer.hpp>
#include "proxy/http/header.h"
#include "proxy/http/github_http_parser.h"
#include <set>

namespace proxy{

  enum ParserState{
    PARSER_STATE_PARSERING,
    PARSER_STATE_ERROR,
    PARSER_STATE_COMPLETE
  };

  /// A Request received from a client.
  struct Request {
    /// The Request method, e.g. "GET", "POST".
    std::string method;

    /// The proxy requested host
    std::string host;

    /// The proxy port
    std::string port;

    /// The Requested URI, such as a path to a file.
    std::string uri;

    /// Major version number, usually 1.
    int http_version_major;

    /// Minor version number, usually 0 or 1.
    int http_version_minor;

    /// The headers included with the Request.
    std::vector<header> headers;

    ParserState state_;

    /// Convert the Reply into a vector of buffers. The buffers do not own the
    /// underlying memory blocks, therefore the Reply object must remain valid and
    /// not be changed until the write operation has completed.
    /// std::vector<boost::asio::const_buffer> to_proxy_buffers();
  };

  struct FakeRequest{
    unsigned char key;
    unsigned char type;
    std::size_t content_length;
    std::string content;
  }; 
  struct FakeResult{
    int state_code;
    std::size_t content_length;
    std::string content;
    unsigned char key;
  };

  class HttpRequestParser{
  public:
    HttpRequestParser();
    virtual ~HttpRequestParser();
    std::size_t Parse(const char* data, int size);
    std::string error_message();
    ParserState State();
    Request &http_request(){ return http_request_; }
  private:
    void InitRequestParser();
  private:
    Request http_request_;
    http_parser parser_;
    http_parser_settings settings_;
    std::set<std::string> remove_set_;
  };
}

#endif // PROXY_CLIENT_HTTP_PARSER_H_